<template>
	<el-container>
		<el-main class="nopadding" style="padding: 30px;">
			<el-card class="box-card" style="margin-top: 20px;">
				<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px">
					<el-form-item label="自购收益比例" prop="level_self">
						<el-input v-model="form.level_self" placeholder="请输入自购收益比例" style="width: 300px;" clearable></el-input>
					</el-form-item>
				</el-form>
				<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px">
					<el-form-item label="一级收益比例" prop="level_one">
						<el-input v-model="form.level_one" placeholder="请输入一级收益比例" style="width: 300px;" clearable></el-input>
					</el-form-item>
				</el-form>
				<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px">
					<el-form-item label="二级收益比例" prop="level_two">
						<el-input v-model="form.level_two" placeholder="请输入二级收益比例" style="width: 300px;" clearable></el-input>
					</el-form-item>
				</el-form>
				<el-button type="primary" :loading="isSaveing" @click="submit()">确定</el-button>
			</el-card>

		</el-main>
	</el-container>
</template>

<script>
	export default {
		name: 'orderList',
		components: {},
		data() {
			return {
				form: {
					id: '',
					level_self: '',
					level_one: '',
					level_two: '',
				},
				isSaveing: false,
				//验证规则
				rules: {
					level_self: [{
						required: true,
						message: '请输入自购收益比例'
					}],
					level_one: [{
						required: true,
						message: '请输入一级收益比例'
					}],
					level_two: [{
						required: true,
						message: '请输入二级收益比例'
					}],
				}
			}
		},
		computed: {},
		mounted() {
			this.getInit()
		},
		methods: {
			//表格内开关
			async getInit(){
				var res = await this.$API.marketing.distribution.index.get();
				if(res.code == 200){
					this.form = {
						id: res.data.id,
						level_self: res.data.level_self,
						level_one: res.data.level_one,
						level_two: res.data.level_two,
					}
				}else{
					this.$alert(res.msg, "提示", {type: 'error'})
				}
			},
			//表单提交方法
			async submit() {
				let valid = await this.$refs.dialogForm.validate().catch(() => {})
				if (!valid) {
					return false
				}
				this.isSaveing = true;
				let res = await this.$API.marketing.distribution.update.post(this.form);
				this.isSaveing = false;
				if (res.code == 200) {
					this.$message.success("操作成功")
				} else {
					this.$alert(res.msg, "提示", {
						type: 'error'
					})
					this.getInit()
				}
			},
		}
	}
</script>

<style lang="scss">
</style>
